package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.Intangible;


public class IntangibleManager extends HibernateDaoSupport {

	public void addIntangible(Intangible intangible) {
		
		getHibernateTemplate().save(intangible);
	}
	
	public void updateIntangible(Intangible intangible) {
		
		getHibernateTemplate().update(intangible);
	}
	
	public void deleteIntangible(int id){
		
		getHibernateTemplate().delete(getIntangible(id));
	}
	
	public Intangible getIntangible(int id){
		Intangible d =(Intangible)getHibernateTemplate().get(Intangible.class, id);
		return d;
	}
	

	@SuppressWarnings("unchecked")
	public List<Intangible> listIntangible() {
		return getHibernateTemplate().find("from Intangible");
	}

	
	@SuppressWarnings("unchecked")	
	public PagerModel pagerList(int start,int limit) {
		List <Intangible>list = getHibernateTemplate().find("from Intangible" );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <Intangible>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	


}



